This forum is closed to new posts and
responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:
A few hints:
Put all the variable declarations in the beginning. You have one right in the middle of your code (FullPath1), which you don't even use.
Remove variables you don't use. FullPath1, s, filesys, path, view and a bunch more are never used.
Declare the variables in a consistent way.
I always declare the Domino objects first, starting with all UI classes, then the backend classes.
Then I declare any custom classes, and finally regular variables in the order they are being used.
I know some prefer to sort the variables alphabetically, but I like to be able to judge where in the code the assignment/usage is based on the sort order.
Try to be consistent with capitalization of variables. I normally use all lower case for variables read from fields/notes items or returned by Lotusscript functions, and CamelCase for other variables.
If you can, group object assignments together:
Set uidoc = ws.CurrentDocument
Set doc = uidoc.document
I also notice that yoru are reading values from teh document using both uidoc.FieldGetText and doc.GetItemValues. Try to be consistent.
You also overwrite the existing field "FileName" (which is a text field initially) with a RichText item... Don't do that, create a new RichText field called "Attachment" instead. Then you would use GetFirstItem() to get a reference to it.
You are also passing arguments to EmbedObject that shold not be used with attachments (the last argument).
All that will make the code much easier to read.
Below is your code cleaned up.
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim filepath As String
Dim filename As String
'*** Save currenly open document
Set uidoc = ws.CurrentDocument
Call uidoc.Save
'*** Get backend document and read field values
Set doc = uidoc.document
filepath = doc.GetItemValue("FullPath")(0) ' Path must end with /
filename = doc.GetItemValue("FileName")(0)
'*** Create a new rich text field called 'Attachment' and save doc
'*** Use GetFirstItem() if the field already exists in document
Set rtitem = New NotesRichTextItem(doc, "Attachment")
Call rtitem.EmbedObject(EMBED_ATTACHMENT,"", filepath + filename)
Call doc.Save(True,True)
End Sub
Don't you agree, much easier to read and follow the code?
Feedback response number WEBB94WM33 created by ~Dan Kikiterobu on 02/14/2013